package innovacion.servlet.idea;

import innovacion.excepcion.DAOExcepcion;
import innovacion.modelo.Idea;
import innovacion.negocio.GestionIdea;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class IdeaEditar
 */
@WebServlet("/IdeaEditarServlet")
public class IdeaEditarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IdeaEditarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String coidea = request.getParameter("id");
		GestionIdea negocio = new GestionIdea();
		try {
			
			if(coidea!=null){
				Collection<Idea> lista = negocio.obtener_idea(coidea);
				
				if(lista.size()>0){
					request.setAttribute("obtener_idea", lista);
					
					}else{
					request.setAttribute("indicador", "2");
				}
			}else{
				request.setAttribute("indicador", "2");
			}					
			
			RequestDispatcher rd = request.getRequestDispatcher("registrar_idea.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			request.setAttribute("mensaje", "5");
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
			
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
